package com.hzcx.app.simplechat.ui.group.LiveData;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.amap.api.services.geocoder.StreetNumber;
import com.hzcx.app.simplechat.ui.group.bean.GroupInfoBean;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.annotations.Nullable;

//public class GroupInfoBeanLiveData extends ViewModel {
//
//    public static Map<String, MutableLiveData<GroupInfoBean>> groupInfoBeanLiveDataMap = new HashMap<>();
//
//    public static MutableLiveData<GroupInfoBean> getGroupInfoBean(GroupInfoBean groupInfoBean) {
//        MutableLiveData<GroupInfoBean> groupInfoBeanLD = groupInfoBeanLiveDataMap.get(groupInfoBean.getGroup_id());
//        if (groupInfoBeanLD == null) {
//            groupInfoBeanLD = new MutableLiveData<GroupInfoBean>();
//            groupInfoBeanLiveDataMap.put(groupInfoBean.getGroup_id(), groupInfoBeanLD);
//        }
//        return groupInfoBeanLD;
//    }
//}

public class GroupInfoBeanLiveData extends ViewModel {

    public static Map<String, GroupInfoBean> groupInfoBeanMap = new HashMap<>();
    public static Map<String, ArrayList<String>> groupMemberIdsMap = new HashMap<>();

    public static GroupInfoBean getGroupInfoBean(GroupInfoBean groupInfoBean) {
        GroupInfoBean groupInfo = getGroupInfoBean(groupInfoBean.getGroup_id());
        if (groupInfo == null) {
            groupInfo = groupInfoBean;
            groupInfoBeanMap.put(groupInfo.getGroup_id(), groupInfo);
        }
        return groupInfo;
    }

    public static GroupInfoBean getGroupInfoBean(String groupID) {
        return groupInfoBeanMap.get(groupID);
    }

    public static void update(@Nullable GroupInfoBean bean) {
        if (bean == null) {
            return;
        }
        groupInfoBeanMap.put(bean.getGroup_id(), bean);
    }

    public static void updateIds(String groupId,ArrayList<String> ids){
        if (ids==null){
            return;
        }
        groupMemberIdsMap.put(groupId,ids);
    }

    public static ArrayList<String> getMemberIds(String groupId){
        return groupMemberIdsMap.get(groupId);
    }
}
